﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DLLPC.Utilities;

namespace COER
{
    public partial class UC_Log : UserControl
    {
        public UC_Log()
        {
            InitializeComponent();
        }

        public void ShowEnable()
        {
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            while (LogHelper.SQ_HMILog.Count > 0)
            {
                string[] strs = LogHelper.SQ_HMILog.Dequeue().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < strs.Length; i++)
                {
                    lbxLog.Items.Insert(i, strs[i]);
                }

                if (lbxLog.Items.Count > 1000)
                {
                    lbxLog.Items.RemoveAt(lbxLog.Items.Count - 1);
                    lbxLog.Items.RemoveAt(lbxLog.Items.Count - 1);
                }

                lbxLog.SelectedIndex = 0;
            }
        }
    }
}
